package cn.snailteam.recruitment.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.snailteam.recruitment.dao.ICompaniesListDAO;
import cn.snailteam.recruitment.entity.CompaniesList;

/**
 * A data access object (DAO) providing persistence and search support for
 * CompaniesList entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see cn.snailteam.recruitment.dao.impl.CompaniesList
 * @author MyEclipse Persistence Tools
 */

public class CompaniesListDAOImpl extends HibernateDaoSupport implements ICompaniesListDAO{
	private static final Log log = LogFactory.getLog(CompaniesListDAOImpl.class);
	// property constants
	public static final String COMPANY_NAME = "companyName";
	public static final String COMPANY_SPECIFICATION = "companySpecification";
	public static final String ESTABLISH_TIME = "establishTime";
	public static final String AREA = "area";
	public static final String ADDRESS = "address";
	public static final String EMAIL = "email";
	public static final String TEL = "tel";
	public static final String DESC_INFO = "descInfo";
	public static final String LOG_PHOTO = "logPhoto";

	protected void initDao() {
		// do nothing
	}

	public void save(CompaniesList transientInstance) {
		log.debug("saving CompaniesList instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(CompaniesList persistentInstance) {
		log.debug("deleting CompaniesList instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public CompaniesList findById(java.lang.Integer id) {
		log.debug("getting CompaniesList instance with id: " + id);
		try {
			CompaniesList instance = (CompaniesList) getHibernateTemplate()
					.get("cn.snailteam.recruitment.dao.impl.CompaniesList", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(CompaniesList instance) {
		log.debug("finding CompaniesList instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding CompaniesList instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from CompaniesList as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCompanyName(Object companyName) {
		return findByProperty(COMPANY_NAME, companyName);
	}

	public List findByCompanySpecification(Object companySpecification) {
		return findByProperty(COMPANY_SPECIFICATION, companySpecification);
	}

	public List findByEstablishTime(Object establishTime) {
		return findByProperty(ESTABLISH_TIME, establishTime);
	}

	public List findByArea(Object area) {
		return findByProperty(AREA, area);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findByTel(Object tel) {
		return findByProperty(TEL, tel);
	}

	public List findByDescInfo(Object descInfo) {
		return findByProperty(DESC_INFO, descInfo);
	}

	public List findByLogPhoto(Object logPhoto) {
		return findByProperty(LOG_PHOTO, logPhoto);
	}

	public List findAll() {
		log.debug("finding all CompaniesList instances");
		try {
			String queryString = "from CompaniesList";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public CompaniesList merge(CompaniesList detachedInstance) {
		log.debug("merging CompaniesList instance");
		try {
			CompaniesList result = (CompaniesList) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(CompaniesList instance) {
		log.debug("attaching dirty CompaniesList instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(CompaniesList instance) {
		log.debug("attaching clean CompaniesList instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CompaniesListDAOImpl getFromApplicationContext(
			ApplicationContext ctx) {
		return (CompaniesListDAOImpl) ctx.getBean("CompaniesListDAO");
	}
}